package com.project.service.impl;

import com.project.bean.CarBean;
import com.project.bean.MasterBean;
import com.project.mapper.IMasterMapper;
import com.project.service.IMasterService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/***
 * 主人实现类
 */
public class IMasterServiceImpl extends BaseService implements IMasterService {
    @Override
    public List<MasterBean> findAll() {
        SqlSession session = this.getSession();
        IMasterMapper mapper =  session.getMapper(IMasterMapper.class);
        List<MasterBean> masterBeans = mapper.findAll();
        session.close();
        return masterBeans;
    }

    @Override
    public void addMaster(MasterBean master, List<CarBean> carList) {
        SqlSession session = this.getSession();
        IMasterMapper mapper =  session.getMapper(IMasterMapper.class);
        mapper.addMaster(master);
        mapper.addCarList(master.getId(),carList);
        session.commit();
        session.close();
    }

    @Override
    public void delCaseCade(int masterId) {
        SqlSession session = this.getSession();
        IMasterMapper mapper =  session.getMapper(IMasterMapper.class);
        mapper.delCaseCade(masterId);
        session.commit();
        session.close();
    }

    @Override
    public void delSetNull(int masterId) {

    }

    @Override
    public MasterBean findById(int id) {
        SqlSession session = this.getSession();
        IMasterMapper mapper =  session.getMapper(IMasterMapper.class);
       MasterBean masterBean = mapper.findById(id);
        return masterBean;
    }
}
